package org.micode.common.enums;

import org.micode.common.helper.I18nMsgHelper;
import org.micode.common.utils.StringExtUtils;

/**
 * API调用结果, 在国际化信息中, 将按照ResultEnum.{code}来定义对应的默认提示信息
 */
public enum ResultEnum {

    /**
     * 200: 成功
     */
    SUCCESS(200, "ok"),

    /**
     * 401: Token无效
     */
    TOKEN_INVALID(401, "Invalid Token"),

    /**
     * 500: 异常
     */
    FAIL(500, "Fail"),

    /**
     * 10000: 请求头中的CLIENT信息不存在
     */
    HEADER_CLIENT_NOT_EXIST(10000, "The client information in the request header does not exist"),

    /**
     * 10001: 解析令牌失败
     */
    DECODE_TOKEN_FAIL(10001, "Failed to resolve token"),

    /**
     * 80000: 授权失败
     */
    AUTH_FAIL(80000, "Privilege grant failed"),

    /**
     * 80300: 获取当前用户信息失败
     */
    GET_USER_FAIL(80300, "Failed to get current user information"),

    /**
     * 80301: 用户信息为空
     */
    USER_EMPTY(80301, "User is empty"),

    /**
     * 100000: 未登录
     */
    UN_LOGIN(100000, "Not logged in"),

    /**
     * 100001: 验证失败
     */
    VERIFY_ERROR(100001, "Validation failed"),

    /**
     * 100002: 没有权限
     */
    PERMISSION_ERROR(100002, "No permission"),

    /**
     * 600001: 非法的类
     */
    INVALID_CLASS(600001, "Illegal class"),

    /**
     * 600002: 处理方法调用失败
     */
    INVOKE_FAIL(600002, "Call failed"),

    /**
     * 600003: 没有找到Bean对象
     */
    NOT_BEAN_FAIL(600003, "Processing class instance not found"),

    /**
     * 900001: 远程服务错误
     */
    REMOTE_ERROR(900001, "Remote service error"),

    /**
     * 900002: 无效的参数
     */
    PARAM_INVALID(900002, "Invalid parameter"),

    /**
     * 900003: 非法的客户端IP
     */
    IP_INVALID(900003, "Illegal client IP"),

    /**
     * 900004: 远程服务调用错误
     */
    REMOTE_INVOKE_FAIL(900004, "Remote service call failed"),

    /**
     * 9999999: 未知错误
     */
    UNKNOWN(999999, "Unknown error"),
    ;

    private int code;

    private String name;

    ResultEnum(int code, String name) {
        this.code = code;
        this.name = name;
    }

    public String getName() {
        String ret = I18nMsgHelper.get(this.getClass().getSimpleName() + "." + code);
        if (StringExtUtils.isAnyEmpty(ret)) {
            return name;
        } else {
            return ret;
        }
    }

    public int getCode() {
        return code;
    }

}
